﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PMS.Utils;
using System.Configuration;

namespace PMS.Utils
{
    public static class ConfigurationConstant
    {
        public const string const_DATE_FORMAT = "SYS_DATE_FORMAT";
        public const string const_DECIMAL_SYMBOL = "SYS_DECIMAL_SYMBOL";
        public const string const_NUMBER_OF_DIGIT = "SYS_NUMBER_OF_DIGIT";
        public const string const_COMPANY_CODE = "SYS_COMPANY_CODE";
        public const string const_SALES_ORGANIZATION = "SYS_SALSE_ORGANIZATION";
        public const string const_DISTRIBUTOR_ID = "SYS_DISTRIBUTOR_ID";
        public const string const_DISTRIBUTOR_NAME = "SYS_DISTRIBUTOR_NAME";
        public const string const_DISTRIBUTOR_PHONE = "SYS_DISTRIBUTOR_PHONE";
        public const string const_DISTRIBUTOR_ADDRESS = "SYS_DISTRIBUTOR_ADDRESS";
        public const string const_DISTRIBUTOR_CHANNEL = "SYS_DISTRIBUTOR_CHANNEL";
        public const string const_NO_OF_DAYS = "SYS_NO_OF_DAYS";
        public const string const_EXCEPT_DAYS = "SYS_EXCEPT_DAYS";


        public static string SYS_DATE_FORMAT;
        public static string SYS_DECIMAL_SYMBOL;
        public static string SYS_NUMBER_OF_DIGIT = "2";
        public static string SYS_COMPANY_CODE;
        public static string SYS_SALES_ORGANIZATION;
        public static string SYS_DISTRIBUTOR_ID;
        public static string SYS_DISTRIBUTOR_NAME;
        public static string SYS_DISTRIBUTOR_PHONE;
        public static string SYS_DISTRIBUTOR_ADDRESS;
        public static string SYS_DISTRIBUTOR_CHANNEL;
        public static string SYS_NO_OF_DAYS;
        public static string SYS_EXCEPT_DAYS;

        public const string const_SD_MODULE_DS_NUMBER_OF_DAYS = "SD_MODULE_DS_NUMBER_OF_DAYS";
        public const string const_SD_MODULE_DS_MAXIMUM_ITEMS = "SD_MODULE_DS_MAXIMUM_ITEMS";
        public const string const_SD_MODULE_SD_GETDATE_DS_ORDER = "SD_MODULE_SD_GETDATE_DS_ORDER";
        public const string const_SD_MODULE_SD_GETDATE_SD_ORDER = "SD_MODULE_SD_GETDATE_SD_ORDER";
        public const string const_SD_MODULE_SD_GETDATE_SC_ORDER = "SD_MODULE_SD_GETDATE_SC_ORDER";
        public const string const_SD_MODULE_SD_GETDATE_CS_ORDER = "SD_MODULE_SD_GETDATE_CS_ORDER";
        public const string const_SD_MODULE_MANUAL_DISCOUNT = "SD_MODULE_MANUAL_DISCOUNT";
        public const string const_SD_MODULE_DEFAULT_SITE = "SD_MODULE_DEFAULT_SITE";
        public const string const_SD_MODULE_DISPLAY_QUANTITY = "SD_MODULE_DISPLAY_QUANTITY";
        public const string const_SD_MODULE_DEFAULT_SITE_LOCATION = "SD_MODULE_DEFAULT_SITE_LOCATION";

        public static string SD_MODULE_DS_NUMBER_OF_DAYS;
        public static string SD_MODULE_DS_MAXIMUM_ITEMS;
        public static string SD_MODULE_SD_GETDATE_DS_ORDER;
        public static string SD_MODULE_SD_GETDATE_SD_ORDER;
        public static string SD_MODULE_SD_GETDATE_SC_ORDER;
        public static string SD_MODULE_SD_GETDATE_CS_ORDER;
        public static string SD_MODULE_MANUAL_DISCOUNT;
        public static string SD_MODULE_DEFAULT_SITE;
        public static string SD_MODULE_DISPLAY_QUANTITY;
        public static string SD_MODULE_DEFAULT_SITE_LOCATION;

        public const string const_TPM_CLAIM_START_DATE = "TPM_CLAIM_START_DATE";
        public const string const_TPM_CLAIM_END_DATE = "TPM_CLAIM_END_DATE";

        public static string TPM_CLAIM_START_DATE;
        public static string TPM_CLAIM_END_DATE;

        public const string const_AR_AUTO_RELEASE = "AR_AUTO_RELEASE";
        public const string const_AP_AUTO_RELEASE = "AP_AUTO_RELEASE";

        public static string AR_AUTO_RELEASE;
        public static string AP_AUTO_RELEASE;

        public const string const_IN_AUTO_RELEASE = "IN_AUTO_RELEASE";

        public static string IN_AUTO_RELEASE;

        public const string const_RGB_SHOP_FORMAT_LEVEL = "RGB_SHOP_FORMAT_LEVEL";
        public const string const_RGB_SITE = "RGB_SITE";

        public static string RGB_SHOP_FORMAT_LEVEL;
        public static string RGB_SITE;

        public const string const_PO_MODULE_DEFAULT_SITE = "PO_MODULE_DEFAULT_SITE";
        public static string PO_MODULE_DEFAULT_SITE;

        public const string const_IN_MODULE_DEFAULT_SITE = "IN_MODULE_DEFAULT_SITE";
        public static string IN_MODULE_DEFAULT_SITE;

        public const string const_IN_MODULE_DISPLAY_QUANTITY = "IN_MODULE_DISPLAY_QUANTITY";
        public static string IN_MODULE_DISPLAY_QUANTITY;

        public static IDictionary<string, string> globalSettings = new Dictionary<string, string>();

        public static string PositiveCurrencyFormatString
        {
            get
            {
                return CurrencyFormatString + ";";
            }
        }

        public static string CurrencyFormatString
        {
            get
            {
                int digit = DataConvertUltils.ToInt32(ConfigurationConstant.SYS_NUMBER_OF_DIGIT);
                return (new String('#', 11).ToString()) + ",###" + (digit > 0 ? "." + (new String('0', digit)).ToString() : string.Empty);
            }
        }
        public static string PositiveCurrencyFormatStringWithoutDigit
        {
            get
            {
                int digit = 0;
                return (new String('#', 11).ToString()) + ",###" + (digit > 0 ? "." + (new String('0', digit)).ToString() : string.Empty);
            }
        }
        public static string PositiveNumericFormatString
        {
            get
            {
                return NumericFormatString + ";";
            }
        }

        public static string NumericFormatString
        {
            get
            {
                return (new String('#', 7).ToString() + ",##0"); //update 18/8/2012 to display numbers over 1 billion (value of the old second parameter in String class is 6)
            }
        }

        public static string DateFormatString
        {
            get
            {
                return string.IsNullOrEmpty(ConfigurationConstant.SYS_DATE_FORMAT) ? "dd/MM/yyyy" : ConfigurationConstant.SYS_DATE_FORMAT;
            }
        }

        public static string PercentRegex
        {
            get
            {
                string symbol = ConfigurationConstant.SYS_DECIMAL_SYMBOL;
                if (!",".Equals(symbol))
                {
                    symbol = "\\.";
                }
                string regex = string.Format("100({0}0{{0,2}}?)?|\\d{{0,2}}({0}\\d{{0,2}})?", symbol);
                return regex;
            }
        }
        private static int m_NotificationDelay;
        public static int NotificationDelay
        {
            get
            {
                try
                {
                    if (m_NotificationDelay <= 0)
                    {
                        m_NotificationDelay = DataConvertUltils.ToInt(ConfigurationManager.AppSettings["NotificationDelay"]);
                        if (m_NotificationDelay <= 0)
                        {
                            m_NotificationDelay = 2000;
                        }
                    }
                }
                catch { m_NotificationDelay = 2000; }

                return m_NotificationDelay;
            }
        }

        public static string PhoneNumberRegex
        {
            get
            {
                return ".{0,20}";
            }
        }

        public static string FaxNumberRegex
        {
            get
            {
                return ".{0,20}";
            }
        }

        public static string CodeBaseRegex
        {
            get
            {
                return "[0-9a-zA-Z./{}_-]";
            }
        }
    }
}
